package c.e.a.b.e.c;

import java.nio.charset.Charset;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/* compiled from: com.google.android.gms:play-services-measurement-base@@18.0.0 */
public final class p6 {
    public static final p6 c = new p6();
    public final r6 a = new r5();
    public final ConcurrentMap<Class<?>, s6<?>> b = new ConcurrentHashMap();

    public final <T> s6<T> a(Class<T> cls) {
        Charset charset = w4.a;
        Objects.requireNonNull(cls, "messageType");
        s6<T> s6Var = (s6) this.b.get(cls);
        if (s6Var != null) {
            return s6Var;
        }
        r5 r5Var = (r5) this.a;
        Objects.requireNonNull(r5Var);
        Class cls2 = u4.class;
        Class cls3 = u6.a;
        if (!cls2.isAssignableFrom(cls)) {
            cls3 = u6.a;
            if (!(cls3 == null || cls3.isAssignableFrom(cls))) {
                throw new IllegalArgumentException("Message classes must extend GeneratedMessage or GeneratedMessageLite");
            }
        }
        c6 b = r5Var.a.b(cls);
        String str = "Protobuf runtime is not correctly loaded.";
        if (b.r()) {
            i6 i6Var;
            f7 f7Var;
            j4 j4Var;
            if (cls2.isAssignableFrom(cls)) {
                f7Var = u6.d;
                j4Var = k4.a;
                i6Var = new i6(f7Var, k4.a, b.s());
            } else {
                f7Var = u6.b;
                j4Var = k4.b;
                if (j4Var != null) {
                    i6Var = new i6(f7Var, j4Var, b.s());
                } else {
                    throw new IllegalStateException(str);
                }
            }
            s6Var = i6Var;
        } else {
            boolean isAssignableFrom = cls2.isAssignableFrom(cls);
            Object obj = null;
            o5 o5Var;
            f7 f7Var2;
            if (isAssignableFrom) {
                if (b.q() == 1) {
                    obj = 1;
                }
                if (obj != null) {
                    k6 k6Var = m6.b;
                    o5Var = o5.b;
                    f7Var2 = u6.d;
                    j4 j4Var2 = k4.a;
                    s6Var = g6.m(b, k6Var, o5Var, f7Var2, k4.a, z5.b);
                } else {
                    s6Var = g6.m(b, m6.b, o5.b, u6.d, null, z5.b);
                }
            } else {
                if (b.q() == 1) {
                    obj = 1;
                }
                if (obj != null) {
                    k6 k6Var2 = m6.a;
                    o5Var = o5.a;
                    f7Var2 = u6.b;
                    j4 j4Var3 = k4.b;
                    if (j4Var3 != null) {
                        s6Var = g6.m(b, k6Var2, o5Var, f7Var2, j4Var3, z5.a);
                    } else {
                        throw new IllegalStateException(str);
                    }
                }
                s6Var = g6.m(b, m6.a, o5.a, u6.c, null, z5.a);
            }
        }
        s6<T> s6Var2 = (s6) this.b.putIfAbsent(cls, s6Var);
        return s6Var2 != null ? s6Var2 : s6Var;
    }

    public final <T> s6<T> b(T t) {
        return a(t.getClass());
    }
}
